package Http;
import java.awt.Color;
import java.awt.image.BufferedImage;

public class Captcha {
	
	private Integer x;
	private Integer y;
	
	public Captcha(){
		x = null;
		y = null;
	}	
	
	public Integer getX(){
		return y;
	}
	
	public Integer getY(){
		return x;
	}
		
        //returns the (X,Y) coordinate of the darkest pixel of the BufferedImage
	public void getCoords(BufferedImage img){
		Color color;
		int rgb,mini=0,minj = 0;
		float min=1, aux=0;
		for(int i=0 ; i < img.getHeight() ; i++ ){
			for(int j=0 ; j < img.getWidth() ; j++){
				rgb = img.getRGB(j, i);
				color = new Color(rgb);
				float[] hsb = null;
				hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
				aux = hsb[2];
				if(aux < min){
					min=aux;
					mini = i;
					minj = j;					
				}					
			}				
		}
		x = mini;
		y = minj;
	}

}

